package com.kjtpay.design_pattern.decorator;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import com.kjtpay.design_pattern.R;
import com.kjtpay.design_pattern.strategy.StrategyActivity;

import java.io.Console;

public class DecoratorActivity extends AppCompatActivity {

    public static void launch(Context context) {
        if (null != context) {
            Intent intent = new Intent();
            intent.setClass(context, DecoratorActivity.class);
            if (!(context instanceof Activity)) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
            context.startActivity(intent);
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_decorator);
        setTitle("装饰模式");
    }

    public void onShowButtonClick(View view) {
        CheckBox checkBoxTShirt = (CheckBox)findViewById(R.id.checkBoxTShirt);
        CheckBox checkBoxTrouser = (CheckBox)findViewById(R.id.checkBoxTrouser);
        CheckBox checkBoxTie = (CheckBox)findViewById(R.id.checkBoxTie);
        CheckBox checkBoxSuit = (CheckBox)findViewById(R.id.checkBoxSuit);
        CheckBox checkBoxSneaker = (CheckBox)findViewById(R.id.checkBoxSneaker);
        CheckBox checkBoxLeatherShoe = (CheckBox)findViewById(R.id.checkBoxLeatherShoe);
        EditText personName = (EditText)findViewById(R.id.editTextPersonName);
        TextView descriptionTextView = (TextView)findViewById(R.id.textViewDescription);

        /* 人物创建 */
        String name = personName.getText().toString();
        Person personXXX = new Person(name);

        TShirt tShirt = new TShirt();
        BigTrouser trouser = new BigTrouser();
        Tie tie = new Tie();
        Suit suit = new Suit();
        Sneaker sneaker = new Sneaker();
        LeatherShoe leatherShoe = new LeatherShoe();

        /* 装饰过程 */
        Person current = personXXX;
        if (checkBoxTShirt.isChecked()) {
            tShirt.decorate(current);
            current = tShirt;
        }
        if (checkBoxTrouser.isChecked()) {
            trouser.decorate(current);
            current = trouser;
        }
        if (checkBoxTie.isChecked()) {
            tie.decorate(current);
            current = tie;
        }
        if (checkBoxSuit.isChecked()) {
            suit.decorate(current);
            current = suit;
        }
        if (checkBoxSneaker.isChecked()) {
            sneaker.decorate(current);
            current = sneaker;
        }
        if (checkBoxLeatherShoe.isChecked()) {
            leatherShoe.decorate(current);
            current = leatherShoe;
        }

        /* 展示 */
        current.show();
        descriptionTextView.setText(current.description);
    }
}